/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pio.action.administrador.instituciones;

import DBMS.DataBaseManager;
import clases.Coordinador;
import clases.Institucion;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

/**
 *
 * @author tamerdark
 */
public class Modificar extends DispatchAction {

    public ActionForward update(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        request.setAttribute("instituciones", Institucion.getAll());
        Institucion c = (Institucion) form;
        DataBaseManager dbms = DataBaseManager.getInstance();
        boolean modificado = dbms.modificarInstitucion(c);
        request.setAttribute("institucion", c);
        if (modificado) {
            c.setMensaje("Institucion modificado exitosamente");
            return mapping.findForward("success");
        } else {
            c.setMensaje("Problemas al modificar la institucion");
            return mapping.findForward("failure");
        }
    }

    public ActionForward populate(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        request.setAttribute("institucion", form);
        request.setAttribute("instituciones", Institucion.getAll());
        return mapping.findForward("failure");
    }
}
